package com.example.demo.bean;

import com.github.llyb120.namilite.config.NamiAuth;
import com.github.llyb120.namilite.config.NamiConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Configuration
public class Nami {
    @Bean
    public NamiConfig namiConfig(){
        return new NamiConfig(){
            //注册热加载的包
            @Override
            public String[] hotPackages() {
                return new String[]{
                    "com.example.demo.ctrl"
                };
            }

            //注册控制器所在包
            @Override
            public String controllerPackage() {
                return "com.example.demo.ctrl";
            }

            @Override
            public NamiAuth namiAuth() {
                return new NamiAuth(){
                    @Override
                    public boolean checkLogin(HttpServletRequest request, HttpServletResponse response) {
                        return Math.random() > 0.5;
                    }

                    @Override
                    public boolean isSu(HttpServletRequest request, HttpServletResponse response) {
                        return false;
//                        return super.isSu(request, response);
                    }
                };
            }
        } ;
    }
}
